<?php if (!defined('THINK_PATH')) exit();?>
<div class="region-input-div wd60 fl">

<div class="layui-input-inline wd100 mb10 layui-form region-item <?php if(($crmsite["regionType"]) != "world"): ?>hidden<?php endif; ?>" lay-filter="country">

	<select name="<?php echo ($FormName); ?>[<?php echo ($form_name); ?>_defaultCountry]" lay-filter="select-country<?php echo $reg; ?>" id="country<?php echo $reg; ?>" lay-ignore>

		<option value=""><?php echo L('PLEASE_SELECT');?></option>

		<?php if(is_array($country)): $i = 0; $__LIST__ = $country;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vc): $mod = ($i % 2 );++$i;?><option value="<?php echo ($vc["code"]); ?>" <?php if(($crmsite["regionType"]) != "world"): if(($vc["code"]) == "1"): ?>selected<?php endif; else: if(($Datainfo[$form_name]['defaultCountry']) == $vc["code"]): ?>selected<?php endif; endif; ?>><?php echo ($vc["name"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>

	</select>

</div>

<div class="layui-input-inline wd100 mb10 <?php if(empty($Datainfo[$form_name]['defaultProv'])): if(($crmsite["regionType"]) == "world"): ?>hidden<?php endif; endif; ?> layui-form region-item" lay-filter="province">

	<select  name="<?php echo ($FormName); ?>[<?php echo ($form_name); ?>_defaultProv]" lay-filter="select-province<?php echo $reg; ?>" id="province<?php echo $reg; ?>" lay-ignore>

		<option value=""><?php echo L('PLEASE_SELECT');?></option>

	</select>

</div>

<div class="layui-input-inline wd100 mb10 <?php if(empty($Datainfo[$form_name]['defaultCity'])): ?>hidden<?php endif; ?> layui-form region-item" lay-filter="city">

	<select  name="<?php echo ($FormName); ?>[<?php echo ($form_name); ?>_defaultCity]" lay-filter="select-city<?php echo $reg; ?>" id="city<?php echo $reg; ?>" lay-ignore>

		<option value=""><?php echo L('PLEASE_SELECT');?></option>


	</select>

</div>

<div class="layui-input-inline wd100 mb10 <?php if(empty($Datainfo[$form_name]['defaultArea'])): ?>hidden<?php endif; ?> layui-form region-item" lay-filter="area">

	<select  name="<?php echo ($FormName); ?>[<?php echo ($form_name); ?>_defaultArea]" lay-filter="select-area<?php echo $reg; ?>" id="area<?php echo $reg; ?>" lay-ignore>

		<option value=""><?php echo L('PLEASE_SELECT');?></option>


	</select>

</div>

</div>

<i class="layui-icon layui-icon-about intro-icon fl blue8 ml10" data-note="<?php echo L('ENTER_NAME_SEARCH');?>"></i>

<script type="text/javascript">

	<?php if(($crmsite["regionType"]) != "world"): if(empty($crmsite["regionType"])): ?>var defaultCountry<?php echo $reg; ?> = "<?php echo ($Datainfo[$form_name]['defaultCountry']); ?>";

		<?php else: ?>

			var defaultCountry<?php echo $reg; ?> = "1";<?php endif; ?>

	<?php else: ?>

		var defaultCountry<?php echo $reg; ?> = "<?php echo ($Datainfo[$form_name]['defaultCountry']); ?>";<?php endif; ?>

	<?php if(empty($Datainfo[$form_name]['defaultProv'])): if(($crmsite["regionType"]) != "world"): ?>var defaultProv<?php echo $reg; ?> = "<?php echo ($province); ?>";

		<?php else: ?>

			var defaultProv<?php echo $reg; ?> = "<?php echo ($Datainfo[$form_name]['defaultProv']); ?>";<?php endif; ?>

	<?php else: ?>

		var defaultProv<?php echo $reg; ?> = "<?php echo ($Datainfo[$form_name]['defaultProv']); ?>";<?php endif; ?>

	var defaultCity<?php echo $reg; ?> = "<?php echo ($Datainfo[$form_name]['defaultCity']); ?>";

	var defaultArea<?php echo $reg; ?> = "<?php echo ($Datainfo[$form_name]['defaultArea']); ?>";

	$("#country<?php echo $reg; ?>").select2();

	$("#province<?php echo $reg; ?>").select2();

	$("#city<?php echo $reg; ?>").select2();

	$("#area<?php echo $reg; ?>").select2();

	$("#country<?php echo $reg; ?>").change(function()
	{
		selectProvince('<?php echo $reg; ?>',"<?php echo U('AjaxRequest/getRegion');?>");
	})

    $("#province<?php echo $reg; ?>").change(function()
	{
		selectCity('<?php echo $reg; ?>',"<?php echo U('AjaxRequest/getRegion');?>");
	})

    $("#city<?php echo $reg; ?>").change(function()
	{
		selectArea('<?php echo $reg; ?>',"<?php echo U('AjaxRequest/getRegion');?>");
	})

	if(defaultCountry<?php echo $reg; ?> && defaultProv<?php echo $reg; ?>)
	{
		$.post("<?php echo U('AjaxRequest/getRegion');?>",{country_id:defaultCountry<?php echo $reg; ?>,type:'province'},function(data)
		{
			if(data.code == 0)
			{
				var option = '<option value=""><?php echo L('SELECT_PROVINCE');?></option>';

				if(data.data.length > 0)
				{
					$.each(data.data,function(k,v)
					{
						if(defaultProv<?php echo $reg; ?>==v.code)
						{
							option += "<option c-value='"+ v.country_code+"' value='"+v.code+"' selected>"+v.name+"</option>";
						}
						else
						{
							option += "<option c-value='"+ v.country_code+"' value='"+v.code+"'>"+v.name+"</option>";
						}

					});

					$('#province<?php echo $reg; ?>').html(option).parents('.region-item').slideDown('fast');

					if(defaultProv<?php echo $reg; ?> && !defaultCity<?php echo $reg; ?>)
					{
						selectCity('<?php echo $reg; ?>',"<?php echo U('AjaxRequest/getRegion');?>");
					}
				}
				else
				{
					$('#province<?php echo $reg; ?>').html(option).parents('.region-item').slideUp('fast');
				}

				$("#province<?php echo $reg; ?>").select2();


			}
		});

		//$('#city<?php echo $reg; ?>').html('<option value=""><?php echo L('SELECT_CITY');?></option>').parents('.region-item').slideUp('fast');
	}
	else
	{
		selectProvince('<?php echo $reg; ?>',"<?php echo U('AjaxRequest/getRegion');?>");
	}

	if(defaultCountry<?php echo $reg; ?> && defaultProv<?php echo $reg; ?> && defaultCity<?php echo $reg; ?>)
	{
		$.post("<?php echo U('AjaxRequest/getRegion');?>",{country_id:defaultCountry<?php echo $reg; ?>,province_id:defaultProv<?php echo $reg; ?>,type:'city'},function(data)
		{
			if(data.code == 0)
			{
				var option = '<option value=""><?php echo L('SELECT_CITY');?></option>';

				if(data.data.length > 0)
				{
					$.each(data.data,function(k,v)
					{
						if(defaultCity<?php echo $reg; ?>==v.code)
						{
							option += "<option c-value='"+ v.country_code+"' p-value='"+ v.province_code+"' value='"+v.code+"' selected>"+v.name+"</option>";
						}
						else
						{
							option += "<option c-value='"+ v.country_code+"' p-value='"+ v.province_code+"' value='"+v.code+"'>"+v.name+"</option>";
						}
					});

					$('#city<?php echo $reg; ?>').html(option).parents('.region-item').slideDown('fast');

					if(defaultCity<?php echo $reg; ?> && !defaultArea<?php echo $reg; ?>)
					{
						selectArea('<?php echo $reg; ?>',"<?php echo U('AjaxRequest/getRegion');?>");
					}
				}
				else
				{
					$('#city<?php echo $reg; ?>').html(option).parents('.region-item').slideUp('fast');
				}

				$("#city<?php echo $reg; ?>").select2();
			}
		});
	}

	if(defaultCountry<?php echo $reg; ?> && defaultProv<?php echo $reg; ?> && defaultCity<?php echo $reg; ?> && defaultArea<?php echo $reg; ?>)
	{
		$.post("<?php echo U('AjaxRequest/getRegion');?>",{country_id:defaultCountry<?php echo $reg; ?>,province_id:defaultProv<?php echo $reg; ?>,city_id:defaultCity<?php echo $reg; ?>,type:'area'},function(data)
		{
			if(data.code == 0)
			{
				var option = '<option value=""><?php echo L('SELECT_AREA');?></option>';

				if(data.data.length > 0)
				{
					$.each(data.data,function(k,v)
					{
						if(defaultArea<?php echo $reg; ?>==v.code)
						{
							option += "<option value='"+v.code+"' selected>"+v.name+"</option>";
						}
						else
						{
							option += "<option value='"+v.code+"'>"+v.name+"</option>";
						}
					});

					$('#area<?php echo $reg; ?>').html(option).parents('.region-item').slideDown('fast');
				}
				else
				{
					$('#area<?php echo $reg; ?>').html(option).parents('.region-item').slideUp('fast');
				}

				$("#area<?php echo $reg; ?>").select2();
			}
		});
	}

</script>